package com.etc.controler;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.etc.service.UserService;
import com.etc.service.impl.UserServiceImpl;
import com.etc.util.Commen;
import com.google.gson.Gson;

/**
 * Servlet implementation class UserDelServlet
 */
@WebServlet("/user/del")
public class UserDelServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private UserService us = new UserServiceImpl();
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	    //设置响应编码
		response.setCharacterEncoding("UTF-8");
		
		//设置json格式
		response.setContentType("application/json");

		Integer uId = 0;
		
		if(request.getParameter("uId")!=null) {
			uId = Integer.parseInt(request.getParameter("uId"));
		}
		
	

		boolean flag = us.removeUserById(uId);
		
		
		Commen cm = new Commen(flag?"删除成功":"删除失败");
		
		Gson gson = new Gson();
		String str = gson.toJson(cm);
		
		PrintWriter out = response.getWriter();
		out.print(str);
		out.close();
		
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		doGet(request, response);
	}
}
